package com.idata.controller;

import cn.hutool.core.collection.ListUtil;
import com.idata.common.constant.Result;
import com.idata.model.enums.AssociationTypeEnum;
import com.idata.model.enums.DisputeSourceEnum;
import com.idata.model.enums.StatisticsTypeForInputEnum;
import com.idata.model.response.DictResponse;
import com.idata.model.response.SelectValue;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.stream.Collectors;

@RestController
public class DictController {

    @PostMapping("/dict")
    @ResponseBody
    public Result<DictResponse> dict() {
        DictResponse dictResponse = new DictResponse();
        dictResponse.setAssociationTypeList(Arrays.stream(AssociationTypeEnum.values())
                .map(type -> new SelectValue(type.getDesc(), type.getCode())).collect(Collectors.toList()));

        dictResponse.setStatisticsTypeList(Arrays.stream(StatisticsTypeForInputEnum.values())
                .map(type -> new SelectValue(type.getName(), type.getCode())).collect(Collectors.toList()));

        dictResponse.setDisputeSourceList(ListUtil.toList(DisputeSourceEnum.POLICE_110, DisputeSourceEnum.COLLABORATIVE_CASE).stream()
                .map(type -> new SelectValue(type.getDesc(), type.getCode())).collect(Collectors.toList()));
        return Result.success(dictResponse);
    }
}
